package fr.umlv.ig.listenerFactory;

import fr.umlv.ig.event.TrainEvent;
import fr.umlv.ig.listener.TrainListener;
import fr.umlv.ig.listener.TrainsListener;
import fr.umlv.ig.metroView.map.MetroMapTrains;
import fr.umlv.ig.model.MetroModel;
import fr.umlv.ig.model.Train;

/**
 * Listener used for the map with trains.
 * @author jenseric
 *
 */
public class MetroMapTrainsListenerFactory {

	/**
	 * Returns a {@link TrainListener} which listen a {@link MetroModel} for
	 * the event with trains. 
	 * @param metroMapTrains the {@link MetroMapTrains} which used the listener
	 * 	      to listen the the MetroModel.
	 * @return a {@link TrainListener} which listen a {@link MetroModel} for the
	 * event with trains.
	 */
	public static TrainListener getTrainListener(final MetroMapTrains metroMapTrains) {
		return new TrainListener() {

			@Override
			public void trainChange(TrainEvent event) {
				
				Train train = (Train) event.getSource();
				if(event.getEventType() == TrainEvent.TRAIN_SELECTED) {
					System.out.println("selectd");
					metroMapTrains.selectTrain(train);
				}
				
				else if(event.getEventType() == TrainEvent.TRAIN_ADDED){
					metroMapTrains.addTrain(train);
					System.out.println("add");
				}
				
				else if(event.getEventType() == TrainEvent.TRAIN_REMOVE) {
				metroMapTrains.removeTrain(train);
				System.out.println("remove");

				}

				else if(event.getEventType() == TrainEvent.TRAIN_UNSELECTED) {
					metroMapTrains.unSelectTrain(train);
					System.out.println("unselkect");
				}

			}
		};
	}

	/**
	 * Listener for listen the move of trains.
	 * @param metroMapTrains the map which listen the MetroModel with the 
	 * Listener returned.
	 * @return listener for listen the move of trains of a MetroModel.
	 */
	public static TrainsListener getTrainsListener(final MetroMapTrains metroMapTrains) {

		return new TrainsListener() {
			@Override
			public void trainsMoved() {
				metroMapTrains.drawWithTransform();
			}
		};
	}
}

